<template>
    <ElTable :data="tableData" class="my-table">
        <ElTableColumn label="权限ID" width="240" prop="id"></ElTableColumn>
        <ElTableColumn label="名称" width="240" prop="title"></ElTableColumn>
        <ElTableColumn label="创建时间" width="240" prop="createTime"></ElTableColumn>
        <ElTableColumn label="创建者" width="240" prop="createUserName"> </ElTableColumn>
        <!-- <ElTableColumn label="注册时间" prop="createTime" width="170"></ElTableColumn> -->
        <ElTableColumn label="操作">
            <template #default>
                <!-- <ElButton type="danger" link>删除</ElButton>
                <ElButton type="primary" link>编辑</ElButton> -->
            </template>
        </ElTableColumn>
    </ElTable>
</template>

<script setup lang="ts">
// import { ElMessageBox, ElMessage } from 'element-plus';

interface Params {
    searchKey: string;
    current: number;
    size: number;
}

const tableData = ref<any[]>([]);

const params = ref<Params>({
    searchKey: '',
    current: 1,
    size: 10,
});

const getData = async (data?: Partial<Params>): Promise<number> => {
    if (data) {
        params.value = { ...params.value, ...data };
    }
    const res = await MyService.account.getPermissionList(params.value);
    if (res.code === 200) {
        tableData.value = res.data.records;
        return res.data.total;
    } else {
        return 0;
    }
};

// const deleteRow = async (roleId: string) => {
//     try {
//         await ElMessageBox.confirm('是否确认删除改角色？', '操作提示', {
//             confirmButtonText: '确认',
//             cancelButtonText: '取消',
//             type: 'warning',
//         });
//         const res = await MyService.account.deleteRole({ id: roleId });
//         if (res.code === 200) {
//             getData({ current: 1 });
//         } else {
//             ElMessage.error({ message: res.msg || '角色删除失败' });
//         }
//     } catch (error) {}
// };

// const assignRolesDialog = ref();

// const assignRoles = async (row: any) => {
//     assignRolesDialog.value?.open(
//         row.id,
//         row.roleList.map((item: any) => item.code)
//     );
// };

defineExpose({
    refresh: getData,
});
</script>

<style scoped>
.img-avatar {
    height: 32px;
    width: 32px;
    border-radius: 16px;
    object-fit: contain;
}
</style>
